/**
 * 
 */
package de.rotkiv.playlistgenerator.logger;

import java.awt.Font;
import java.util.Iterator;
import java.util.List;

import javax.swing.JTextArea;


/**
 * @author Rotkiv
 *
 */
public class TextAreaLogger implements IF_StatusLogging {

	private static final String ERROR 	= "[ERROR]";
	private static final String CR 		= "\n";
	private static final String SPACES 	= "    ";

	private JTextArea textArea;


	public TextAreaLogger(JTextArea textArea) {
		this.textArea = textArea;
		init();
	}


	private void init() {
		Font font = new Font("monospaced", Font.PLAIN, 12);
		textArea.setFont(font);
	}


	@Override
	public void log(String msg) {
		log(msg, false);
	}

	@Override
	public void log(String msg, boolean error) {
		textArea.append(CR);
		if (error) {
			textArea.append(ERROR);
		}
		textArea.append(msg);
	}

	@Override
	public void log(List<String> list, boolean error) {
		if (list == null) {
			return;
		}
		Iterator<String> it = list.iterator();
		while (it.hasNext()) {
			String temp = SPACES + it.next();
			log(temp, error);
		}
	}

}
